using System.Collections.Generic;
using UnityEngine;

public class Name : MonoBehaviour
{
    private static Dictionary<string, GameObject> _map = new Dictionary<string, GameObject>();
    public static GameObject Get(string name)
    {
        if (_map.TryGetValue(name, out GameObject go))
        {

        }
        return go;
    }
    public string ID;
    public Color Color = Color.red;
    private string _id;
    private void Start()
    {
        _id = this.ID;
        if (string.IsNullOrEmpty(_id)) return;
        if (!_map.ContainsKey(_id))
        {
            _map.Add(_id, this.gameObject);
            return;
        }
        _map[_id] = this.gameObject;
    }
    private void OnDestroy()
    {
        if (string.IsNullOrEmpty(_id)) return;
        if (_map.ContainsKey(_id))
        {
            _map.Remove(_id);
        }
    }
    private void OnDrawGizmos()
    {
        var p1 = this.transform.position;
        var p2 = this.transform.position - this.transform.forward - this.transform.right;
        var p3 = this.transform.position - this.transform.forward + this.transform.right;
        var color = this.Color;
        if (ID == null)
        {
            color = Color.gray;
        }
        Gizmos.color = color;
        Gizmos.DrawLine(p1, p2);
        Gizmos.DrawLine(p1, p3);
        Gizmos.DrawLine(p2, p3);
    }
}